package main

import (
	"log"
	"reflect"
)

type aa struct {
}

func (a *aa) GetID() int32 {
	return 1
}

type getID interface {
	GetID() int32
}

func print(g getID) {
	log.Println(g.GetID())
}

func prints(gs []getID) {
	for _, g := range gs {
		log.Println(g.GetID())
	}
}

func toGetIDs(i interface{}) []getID {
	sv := reflect.ValueOf(i)

	if sv.Kind() != reflect.Slice {
		log.Fatal("参数不是 Slice")
	}

	objs := make([]getID, sv.Len())
	s := reflect.ValueOf(i)

	for i := 0; i < s.Len(); i++ {
		ele := s.Index(i)
		objs[i] = ele.Interface().(getID)
	}

	return objs
}

func main() {
	a := &aa{}
	print(a)
	aas := []*aa{a}
	as := []getID{}
	// as=append(as, aas...)
	for _, f := range aas {
		as = append(as, f)
	}
	// prints(toGetIDs(as))
	prints(as)
	prints(toGetIDs(aas))
}
